<?php
require 'functions.php';

$session = new \Models\MySession();

if (isset($_GET['author_id'])) {
    $authors = new Models\Authors();
   $q = $authors->allBooksOfAuthor($_GET['author_id']);   
} else {
     $books = new Models\Books();
     $q = $books->getAllBooks(1);
}

$data = [];
foreach ($q as $row) {
    $data['carti'][$row['id_carte']]['titlu'] = $row['titlu'];
    $data['carti'][$row['id_carte']]['autori'][$row['id_autor']] = $row['nume']." ".$row['prenume'];
}

$data['userGreeting'] = '';
if($_SESSION and !empty($_SESSION['userId'] )){
    try {
        $userName = Models\User::getUserName($_SESSION['userId']); 
        $data['userGreeting'] = 'Hi <b>'.$userName.'</b>';   
    } catch (Exception $exc) {
        echo $exc->getMessage();
    }
}


@$data['isLogged'] = $_SESSION['isLogged'];


$data['title'] = 'Biblioteca Academiei Tehnice Miltiare';
$data['content'] = './public_html/index_public.php';
$data['header'] = './inc/header.php';
render($data, $layout);
